package com.bw.shopping.mvvm.viewmodel;

import androidx.databinding.ObservableField;

import com.bw.mvvm_common.entity.BaseEntity;
import com.bw.mvvm_common.mvvm.utils.GreenDaoUtils;
import com.bw.mvvm_common.mvvm.viewmodel.BaseViewModel;
import com.bw.shopping.entity.CompileEntity;
import com.bw.shopping.mvvm.model.CompileModel;

import java.util.HashMap;

import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.schedulers.Schedulers;

public

/**
 * @author Lishaohe
 * @description:
 * @date :2021/10/31 0031 下午 5:52
 */
class CompileViewModel extends BaseViewModel<CompileModel> {
    int  id;
    public ObservableField<String>name = new ObservableField<>();
    public ObservableField<String>phone = new ObservableField<>();
    public ObservableField<String>address = new ObservableField<>();

    @Override
    protected void result(BaseEntity entity) {
        if (entity instanceof CompileEntity){

        }
    }

    public void editAddress(){
        int user_id = GreenDaoUtils.getGreenDaoUtils().green().queryBuilder().list().get(0).getUser_id();
        HashMap<String,Object> map = new HashMap<>();
        map.put("id",id);
        map.put("shipAddress",address.get());
        map.put("shipIsDefault",1);
        map.put("shipUserMobile",phone.get());
        map.put("shipUserName",name.get());
        map.put("userId",user_id);
        m.requestCompile(map)
                .observeOn(AndroidSchedulers.mainThread())
                .subscribeOn(Schedulers.io())
                .subscribe(this);
    }

    public void save(){
        editAddress();
        finishPage();
    }

    public void finish(){
        finishPage();
    }

    public void getid(int addressid){
        id = addressid;
    }
}
